package com.itheima.web;

import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import com.itheima.support.QueryPageBean;
import com.itheima.support.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/checkitem")
@Api(tags = "检查项")
public class CheckItemController {

    @Reference
    private CheckItemService checkItemService;

    @PostMapping("/add")
    @ApiOperation("新增检查项")
    public boolean add(@RequestBody CheckItem checkItem){
        return checkItemService.save(checkItem);
    }

    @PostMapping("/edit")
    public boolean edit(@RequestBody CheckItem checkItem){
        return checkItemService.updateById(checkItem);
    }

    @PostMapping("/save")
    public Result save(@RequestBody CheckItem checkItem){
        //1.第一步根据主键查询数据是否存在
        //2.如果数据存在则进行修改
        return new Result(checkItemService.saveOrUpdate(checkItem));
    }

    @GetMapping("/findAll")
    public List<CheckItem> findAll(){
        return checkItemService.findAll();
    }

    @PostMapping("/findByPage")
    public Result findByPage(@RequestBody QueryPageBean pageBean){
        return new Result(checkItemService.findByPage(pageBean));
    }

    @GetMapping("/deleteById/{id}")
    public boolean deleteById(@PathVariable Long id){

        return checkItemService.deleteById(id);
    }

}
